package com.svs.web.controller.project;

import java.util.List;

import com.svs.common.utils.ExcelUtil;
import com.svs.framework.shiro.util.ShiroUtils;
import com.svs.project.domain.Counter;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import com.svs.common.annotation.Log;
import com.svs.common.enums.BusinessType;
import com.svs.project.domain.ProLine;
import com.svs.project.service.ProLineService;
import com.svs.framework.web.BaseController;
import com.svs.framework.web.page.TableDataInfo;
import com.svs.common.base.AjaxResult;

/**
 * 生产线管理 信息操作处理
 * 
 * @author 杜建桥
 * @date 2023-08-12
 */
@Controller
@RequestMapping("/project/proLine")
public class ProLineController extends BaseController {

    private String prefix = "project/proLine";
	
	@Autowired
	private ProLineService proLineService;
	
	@RequiresPermissions("project:proLine:view")
	@GetMapping()
	public String proLine() {
	    return prefix + "/proLineList";
	}
	
	/**
	 * 查询生产线管理列表
	 */
	@RequiresPermissions("project:proLine:list")
	@PostMapping("/list")
	@ResponseBody
	public TableDataInfo list(ProLine proLine) {
		startPage();
        List<ProLine> list = proLineService.selectAllList(proLine);
		return getDataTable(list);
	}
	
	/**
	 * 新增生产线管理
	 */
	@GetMapping("/add")
	public String add() {
	    return prefix + "/addProLine";
	}
	
	/**
	 * 新增保存生产线管理
	 */
	@RequiresPermissions("project:proLine:add")
	@Log(title = "生产线管理", businessType = BusinessType.INSERT)
	@PostMapping("/add")
	@ResponseBody
	public AjaxResult addSave(ProLine proLine) {
		proLine.setCreateBy(ShiroUtils.getLoginName());
		return toAjax(proLineService.save(proLine));
	}

	/**
	 * 修改生产线管理
	 */
	@GetMapping("/edit/{id}")
	public String edit(@PathVariable("id") Long id, ModelMap mmap) {
		ProLine proLine = proLineService.selectByPrimaryKey(id);
		mmap.put("proLine", proLine);
	    return prefix + "/editProLine";
	}
	
	/**
	 * 修改保存生产线管理
	 */
	@RequiresPermissions("project:proLine:edit")
	@Log(title = "生产线管理", businessType = BusinessType.UPDATE)
	@PostMapping("/edit")
	@ResponseBody
	public AjaxResult editSave(ProLine proLine) {
		proLine.setUpdateBy(ShiroUtils.getLoginName());
		return toAjax(proLineService.update(proLine));
	}
	
	/**
	 * 删除生产线管理
	 */
	@RequiresPermissions("project:proLine:remove")
	@Log(title = "生产线管理", businessType = BusinessType.DELETE)
	@PostMapping( "/remove")
	@ResponseBody
	public AjaxResult remove(String[] ids) {		
		return toAjax(proLineService.deleteByPrimaryKeys(ids));
	}

	@Log(title = "生产线管理", businessType = BusinessType.EXPORT)
	@RequiresPermissions("project:proLine:export")
	@PostMapping("/export")
	@ResponseBody
	public AjaxResult export(ProLine proLine) {
		List<ProLine> list = proLineService.selectAllList(proLine);
		ExcelUtil<ProLine> util = new ExcelUtil<>(ProLine.class);
		return util.exportExcel(list, "proLine");
	}
}
